<?php
include_once(dirname(__FILE__).'/../../autoload.php');

/**
 * Description of RegistryTest
 *
 * @author joona
 * @runInSeparateProcess
 */
class Unit_Core_RequestTest extends Lib_UnitTestcase
{
    public function setup()
    {
        $this->classUnderTest = new Core_Request('',
            $this->getFakeGetData(),
            $this->getFakePostData()
        );
        $this->classUnderTest->setValidationRules(array(
            'why' => array(), 'id' => array(), 'empty' => array('allowNull' => true),
            'method' => array()
        ));
    }
    public function tearDown()
    {
        $this->classUnderTest->resetValidationRules();
    }

    private function getFakeGetData()
    {
        return array(
            'why' => 'Cos I can!',
            'id' => 47,
            'empty' => ''
        );
    }
    private function getFakePostData()
    {
        return array(
            'method' => 'post',
            'id' => 99,
            'empty' => ''
        );
    }
    public function test_getGetData_single()
    {
        $expected = 'Cos I can!';
        $actual = $this->classUnderTest->getGetData('why');
        $this->assertEquals($actual, $expected);
    }
    public function test_getGetData_all()
    {
        $expected = $this->getFakeGetData();
        $actual = $this->classUnderTest->getGetData();
        $this->assertEquals($actual, $expected);
    }

    public function test_getGetData_null()
    {
        $this->assertEquals(null, $this->classUnderTest->getGetData('nonExisting'));
    }

    public function test_getPostData_null()
    {
        $this->assertEquals(null, $this->classUnderTest->getPostData('nonExisting'));
    }

    public function test_getPostData_single()
    {
        $expected = 'post';
        $actual = $this->classUnderTest->getPostData('method');
        $this->assertEquals($actual, $expected);
    }
    public function test_getPostData_all()
    {
        $expected = $this->getFakePostData();
        $actual = $this->classUnderTest->getPostData();
        $this->assertEquals($actual, $expected);
    }

    public function test_replaceEmptyStringsWithNulls()
    {
        $expectedPost = array(
            'method' => 'post',
            'id' => 99,
            'empty' => null
        );
        $expectedGet = array(
            'why' => 'Cos I can!',
            'id' => 47,
            'empty' => null
        );
        $this->classUnderTest->replaceEmptyStringsWithNulls();
        $this->assertEquals($expectedPost, $this->classUnderTest->getPostData());
        $this->assertEquals($expectedGet, $this->classUnderTest->getGetData());
    }
}
